<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        .warp {
            width: 350px;
            height: 260px;
        }
        
        .nav {
            width: 350px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            display: flex;
        }
        
        .nav li {
            list-style: none;
            flex: 1;
            border-bottom: 1px solid #aaa;
        }
        
        .nav .active {
            border-bottom: 3px solid #3f48cc;
        }
        
        .partBox {
            height: 260px;
        }
        
        .partBox>div {
            width: 350px;
            height: 150px;
            line-height: 150px;
            display: none;
        }
        
        .partBox .show {
            display: block;
        }
        
        .show .tab1,
        .tab2 {
            height: 30px;
            width: 100%;
        }
        
        .tab1 span {
            color: aqua;
            margin-left: 30px;
        }
        
        .tab2 span {
            color: aqua;
            margin-left: 30px;
        }
    </style>
</head>



<body>

    <div class="wrap">
        <div class="nav">
            <li class="active">考点周边交通路线</li>
            <li>驾车出行交通管制</li>

        </div>
        <div class="partBox">
            <div class="show">
                <div class="tab1">
                    考点A <span>点击查看</span>
                </div>
                <div class="tab1">
                    考点B <span>点击查看</span>
                </div>

            </div>
            <div>part_02</div>

        </div>
    </div>

</body>


<script>
    //测试
    var nav = document.getElementsByClassName("nav")[0];
    var liList = nav.getElementsByTagName("li");

    var partList = document.querySelectorAll(".partBox>div")
    for (let i = 0; i < liList.length; i++) {
        let li = liList[i];
        li.onclick = function() {
            console.log(li, i);

            // 先把liList所有的li的class清空 
            // 先把 partList所有的div的class清空 
            for (let j = 0; j < liList.length; j++) {
                liList[j].className = "";
                partList[j].className = "";
            }

            // 再把liList当前li改为活跃状态
            // 再把partList对应下标的div改为活跃状态
            this.className = "active";
            partList[i].className = "show";
        }
    }
</script>

</html>